package com.linwen.javase.desgin_pattern.BigTalkDesignPattenJAVACode._17单例模式._2基本代码;

//单例模式类
class Singleton {

    private static Singleton instance;

    //构造方法private化
    private Singleton() {
    }

    //得到Singleton的实例（唯一途径）加锁，保证唯一
    public static synchronized Singleton getInstance() {

        if (instance == null) {
            instance = new Singleton();
        }

        return instance;
    }
}